package com.fireXXX.job.analysis.crawler.boss;

import com.fireXXX.job.analysis.crawler.boss.data.OriginJobItem;
import com.fireXXX.job.analysis.crawler.util.JacksonUtil;
import com.fireXXX.job.analysis.data.api.job.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Component
@Slf4j
public class JobParser {

    public List<Job> parse(List<OriginJobItem> items) {
        return Optional.ofNullable(items).orElse(Collections.emptyList()).stream().map(item -> {
            Job job = new Job();

            Company company = new Company();
            company.setSource(SourceTypeEnum.BOSS);
            company.setBenefits(item.getCompany().getBenefits());
            company.setEmployeeNumber(item.getCompany().getEmployeeNumber());
            company.setName(item.getCompany().getName());
            company.setPublicStep(item.getCompany().getPublicStep());
            company.setIndustry(item.getCompany().getIndustry());

            job.setCompanyDetail(JacksonUtil.toJsonStringSafe(company));
            job.setSource(SourceTypeEnum.BOSS);
            job.setArea(item.getArea());
            job.setDetailUrl(item.getDetailUrl());
            job.setEducation(item.getEducation());
            job.setExperiences(item.getExperiences());
            job.setPublishTime(item.getPublishTime());
            job.setName(item.getName());
            job.setSalary(item.getSalary());
            job.setRecruitersName(item.getRecruitersName());
            job.setRecruitersJob(item.getRecruitersJob());
            job.setTags(item.getTags());

            return job;
        }).collect(Collectors.toList());
    }

}
